#include "ui_text.h"

CUIText::CUIText(const string &szText, const string &szFontName)
    : m_szText(szText),
      m_pFont(nullptr)
{
    /**
     * @param const string &szText The text this UI element represents
     * @param const string &szFontName The name of the font to use
     */
    m_pFont = CFontManager::getInstance()->getFont(szFontName);
}

CUIText::CUIText(const string &szText, CFont *pFont)
    : m_szText(szText),
      m_pFont(pFont)
{
    /**
     * @param const string &szText The text this UI element represents
     * @param CFont *pFont The font to use to display the text
     */
}

const string &CUIText::getText() const
{
    /**
     * @return string The text this UI element represent
     */
    return m_szText;
}

void CUIText::setText(const string &szText)
{
    /**
     * @param string szText THe new text value this object holds
     */
    m_szText = szText;
}

CFont *CUIText::getFont() const
{
    /**
     * @return CFont *The current font object used to render the text
     */
    return m_pFont;
}

void CUIText::setFont(CFont *pFont)
{
    /**
     * @param CFont *pFont The new font to render the text in
     */
    m_pFont = pFont;
}

void CUIText::render()
{
    /**
     * Renders the text at the colour and position of the text.
     */
    RECT rect;

    if (! isVisible())
    {
        return;
    }

    rect.left = static_cast<long>(getPositionLeft());
    rect.top = static_cast<long>(getPositionTop());
    rect.right = static_cast<long>(rect.left + getWidth());
    rect.bottom = static_cast<long>(rect.top + getHeight());

    if (m_pFont != nullptr)
    {
        m_pFont->drawText(getText(), &rect, D3DCOLOR_ARGB(
            static_cast<int>(getAlpha()), static_cast<int>(getRed()), 
            static_cast<int>(getGreen()), static_cast<int>(getBlue())));
    }

    renderChildren();
}